package goleetcode

import "golang.org/x/exp/slices"

func findMinimumTime(tasks [][]int) int {
	slices.SortFunc(tasks, func(a, b []int) int {return a[1] - b[1]})
	run := make([]bool, tasks[len(tasks) - 1][1] + 1)
	ans := 0
	for _ ,t := range tasks {
		start, end, d := t[0], t[1], t[2]
		for _, b := range run[start : end + 1] {
			if b {
				d--
			}
		}
		for i := end; d > 0; i-- {
			if !run[i] {
				run[i] = true
				d--
				ans++
			}
		}
	} 
	return ans
}